package cn.silver.module.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.silver.framework.log.annotation.Log;
import cn.silver.framework.log.enums.OperateEnums;
import cn.silver.framework.mybatis.controller.DataController;
import cn.silver.framework.openapi.model.Result;
import cn.silver.module.system.domain.SysUser;
import cn.silver.module.system.bean.UserBean;
import cn.silver.module.system.param.UserParam;
import cn.silver.module.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户信息
 *
 * @author Silver Zhou
 */
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "系统管理-用户管理")
@RequestMapping("/system/user")
public class SysUserController extends DataController<ISysUserService, SysUser, UserParam, UserBean> {

    @Resource
    @Override
    public void setBaseService(ISysUserService baseService) {
        this.setPermission("system:user");
        this.setCode("system_user");
        this.setTitle("系统管理-用户管理");
        this.baseService = baseService;
    }

    /**
     * 重置密码
     */
    @SaCheckPermission("system:user:resetPwd")
    @Log(title = "用户管理", operate = OperateEnums.ALTER_UPDATE)
    @PostMapping("/resetPwd/{userIds}")
    public Result<Void> resetPwd(@PathVariable String[] userIds) {
        baseService.resetUserPwd(List.of(userIds));
        return Result.ok();
    }
}
